package com.eagle.coders.core.type;

import java.util.Date;

/**
 * This enum class is to store the constant values for field
 * 
 * @author evelyn wong
 *
 */
/*
 * ==================================================================================
 * HISTORY
 * ----------------------------------------------------------------------------------
 * Date         Author   Remarks
 * ----------------------------------------------------------------------------------
 * 2008/01/14   evelyn   moved this class fromn System project
 *                       added getFieldType();
 * 2008/01/22   wkteoh   add in S and B field type
 * 2008/03/03   evelyn   added getFieldClass()
 * ==================================================================================
 */
public enum FieldType {

    NUMBER("N", Double.class), CHARACTER("C", String.class), DATE("D", Date.class), RANGE("R",
            Double.class), FREE_FORMAT("F", String.class), BOOLEAN("B", String.class), INTEGER("I",
            Integer.class), RATE("L", Double.class);

    private String value;
    private Class javaClass;

    FieldType(String value, Class javaClass) {
        this.value = value;
        this.javaClass = javaClass;
    }

    public String getValue() {
        return value;
    }

    public static FieldType getFieldType(String fieldTypeValue) {

        final FieldType[] fieldTypes = FieldType.values();

        FieldType selectedFieldType = null;

        for (final FieldType fieldType : fieldTypes) {
            if (fieldType.getValue().equals(fieldTypeValue)) {
                selectedFieldType = fieldType;
                break;
            }
        }

        return selectedFieldType;

    }

    /**
     * get the java represented class for the field type
     * @param fieldTypeValue
     * @return
     */
    public static Class getFieldClass(String fieldTypeValue) {
        FieldType fieldType = getFieldType(fieldTypeValue);
        
        if (null != fieldType) {
            return fieldType.javaClass;
        }
        return null;
    }
}
